package com.tanhua.server.controller;

import com.tanhua.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author anshuai
 * @create 2021-02-04 18:11
 */
@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 消息-添加联系人（添加好友）
     * POST /messages/contacts
     */
    @PostMapping("/contacts")
    public ResponseEntity addContact(@RequestBody Map map){
        Long targetUserId = Long.valueOf(map.get("userId").toString());
        return messageService.addContact(targetUserId);
    }

    /**
     * 消息-联系人列表(查询好友)
     * GET /messages/contacts
     */
    @GetMapping("/contacts")
    public ResponseEntity findContactList(@RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int pagesize,
                                          @RequestParam(required = false) String keyword){
        return messageService.findContactList(page,pagesize,keyword);
    }

    /**
     * 消息-点赞列表（commentType 1）
     * GET /messages/likes
     */
    @GetMapping("/likes")
    public ResponseEntity findLikeList(@RequestParam(defaultValue = "1") int page,
                                       @RequestParam(defaultValue = "10") int pagesize){
        return messageService.findCommentList(page,pagesize,1);
    }

    /**
     * 消息-评论列表（commentType 2）
     * GET /messages/comments
     */
    @GetMapping("/comments")
    public ResponseEntity findCommentsList(@RequestParam(defaultValue = "1") int page,
                                           @RequestParam(defaultValue = "10") int pagesize){
        return messageService.findCommentList(page,pagesize,2);
    }

    /**
     * 消息-喜欢列表（commentType 3）
     * GET /messages/loves
     */
    @GetMapping("/loves")
    public ResponseEntity findLoveList(@RequestParam(defaultValue = "1") int page,
                                       @RequestParam(defaultValue = "10") int pagesize){
        return messageService.findCommentList(page,pagesize,3);
    }

    /**
     * 消息-公告列表
     * GET /messages/announcements
     */
    @GetMapping("/announcements")
    public ResponseEntity findAnnouncementsList(@RequestParam(defaultValue = "1") int page,
                                                @RequestParam(defaultValue = "10") int pagesize){
        return messageService.findAnnouncementsList(page,pagesize);
    }
}
